﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MathNet.Numerics.LinearAlgebra.Generic;
using MathNet.Numerics.LinearAlgebra.Double;

namespace CubeRotation
{
    public class Cube
    {
        private Point[] points;

        public Point this[int index]
        {
            get
            {
                return points[index];
            }
            set
            {
                points[index] = value;
            }

        }

        // Cube instance construction
        public Cube()
        {
            double halfSize = 0.5;
            Point[] points = new Point[8];

            points[0] = new Point(halfSize, halfSize, halfSize);
            points[1] = new Point(halfSize, halfSize, -halfSize);
            points[2] = new Point(halfSize, -halfSize, halfSize);
            points[3] = new Point(halfSize, -halfSize, -halfSize);
            points[4] = new Point(-halfSize, halfSize, halfSize);
            points[5] = new Point(-halfSize, halfSize, -halfSize);
            points[6] = new Point(-halfSize, -halfSize, halfSize);
            points[7] = new Point(-halfSize, -halfSize, -halfSize);

            this.points = points;
        }

        public static Cube CreateCube(double translationDistance, double angleX, double angleY, double angleZ)
        {
            Cube cube = new Cube();

            cube.RotateZ(angleX);
            cube.RotateY(angleY);
            cube.RotateX(angleZ);

            cube.Translate(translationDistance);

            return cube;
        }

        // Translation method
        public void Translate(double dist)
        {
            for (int i = 0; i < 8; i++)
            {
                points[i].X += dist;
                points[i].Y += dist;
                points[i].Z += dist;
            }
        }

        public void RotateX(double angle)
        {
            for (int i = 0; i < 8; i++)
            {
                this.points[i] = MathTools.RotateX(this.points[i], angle);
            }
        }

        public void RotateY(double angle)
        {
            for (int i = 0; i < 8; i++)
            {
                this.points[i] = MathTools.RotateY(this.points[i], angle);
            }
        }

        public void RotateZ(double angle)
        {
            for (int i = 0; i < 8; i++)
            {
                this.points[i] = MathTools.RotateZ(this.points[i], angle);
            }
        }

        public void Print()
        {
            for (int i = 0; i < 8; i++)
            {
                points[i].Print();
            }
        }

    }
}
